window.onload = function() {
    menuId = location.href.split("?")[1]
    $("#exportList").attr("href", "/operation/event/pending/export?menuId=" + menuId + "&search=")
    if (location.href.split("?")[0].indexOf("monthCommonDemond") > -1) {
        var title = "对应部门"
    } else {
        var title = "系统通道"
    }
    var booleanVal = false; //是否点击跳转标记
    var columns = [
        { field: 'eventId', title: '事件编号', align: "center" },
        { field: 'menuName', title: '菜单', align: "center" },
        { field: 'channelName', title: title, align: "center" },
        { field: 'questionName', title: '问题类别', align: "center" },
        { field: 'eventTheme', title: '事件主题', align: "center" },
        { field: 'insertTime', title: '提交时间', align: "center" },
        { field: 'insertUserName', title: '提交人', align: "center" },
        { field: 'orgName', title: '提交机构', align: "center" },
        { field: 'processUserName', title: '处理人', align: "center" },
        { field: 'processOrgName', title: '处理部门', align: "center" },
        { field: 'status', title: '状态', align: "center" }
    ]
    tableData = {
        initData: function(a) {
            $('#table').bootstrapTable({
                method: 'get',
                contentType: 'application/json',
                url: "/operation/event/pending/",
                dataField: "data",
                pageNumber: 1,
                cache: false,
                escape: true,
                pagination: true,
                queryParams: function(params) {
                    return {
                        pageSize: params.limit,
                        page: params.offset / params.limit + 1,
                        search: $("#searchVal").val() == "可支持事件编号、事件主题、提交时间、处理人、状态搜索" ? "" : $("#searchVal").val(),
                        menuId: menuId
                    }
                },
                sidePagination: 'server',
                pageSize: 10,
                pageList: [10, 20, 50],
                responseHandler: function(result) {

                    var errcode = result.message;
                    var transDateRes = result.data.list;
                    for (var i = 0; i < transDateRes.length; i++) {
                        transDateRes[i]["insertTime"] = moment(transDateRes[i]["insertTime"]).format('YYYY-MM-DD HH:mm:ss')

                        if (transDateRes[i]["status"] == "11") {
                            transDateRes[i]["status"] = "已保存"
                        } else if (transDateRes[i]["status"] == "12") {
                            transDateRes[i]["status"] = "已提交"
                        } else if (transDateRes[i]["status"] == "13") {
                            transDateRes[i]["status"] = "已回退"
                        } else if (transDateRes[i]["status"] == "21") {
                            transDateRes[i]["status"] = "待处理"
                        } else if (transDateRes[i]["status"] == "22") {
                            transDateRes[i]["status"] = "已分发"
                        } else if (transDateRes[i]["status"] == "23") {
                            transDateRes[i]["status"] = "待确认"
                        } else if (transDateRes[i]["status"] == "30") {
                            transDateRes[i]["status"] = "已处理"
                        } else if (transDateRes[i]["status"] == "90") {
                            transDateRes[i]["status"] = "已解决"
                        } else if (transDateRes[i]["status"] == "91") {
                            transDateRes[i]["status"] = "未解决"
                        }
                    }
                    if (errcode == "成功") {

                        return {
                            total: result.data.conf.totalNum,
                            data: transDateRes
                        };
                    } else {
                        alert("错误代码" + errcode);
                        return;
                    }
                },
                paginationPreText: "上一页",
                paginationNextText: "下一页",
                showHeader: true,
                columns: columns,
                onClickRow: function(row, $element) {
                    defaultParams = row
                    $($element).addClass("changeColor").siblings().removeClass("changeColor")
                    if (booleanVal) {
                        $("#buttonDetail").click()
                    }
                },
                onClickCell: function(row, $element) {
                    if (row == "eventId") {
                        booleanVal = true
                    } else {
                        booleanVal = false
                    }
                },
                onDblClickRow: function(data) {
                    $("#buttonDetail").click()
                }
            });
        }
    }

    tableData.initData()

    //
}

function isDetailAuto(booleanVal) { //是否自动点击详情
    if (booleanVal) {
        $("#buttonDetail").click()
    }
}
